AddToAny Method (BlockingCollection(T)[], T, CancellationToken)

Task Parallel System.Threading

Adds the specified item to any one of the specified BlockingCollection<(Of <(T>)>) instances. A OperationCanceledException is thrown if the CancellationToken is canceled.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function AddToAny ( _
	collections As BlockingCollection(Of T)(), _
	item As T, _
	cancellationToken As CancellationToken _
) As Integer
C#
public static int AddToAny(
	BlockingCollection<T>[] collections,
	T item,
	CancellationToken cancellationToken
)

Parameters

collections
Type: array< System.Collections.Concurrent..::.BlockingCollection<(Of <(T>)>) >[]()[]
The array of collections.
item
Type: T
The item to be added to one of the collections.
cancellationToken
Type: System.Threading..::.CancellationToken
A cancellation token to observe.

Return Value

The index of the collection in the collections array to which the item was added.

Remarks

If a bounded capacity was specified when all of the BlockingCollection<(Of <(T>)>) instances were initialized, a call to AddToAny may block until space is available in one of the collections to store the provided item.

Exceptions

ExceptionCondition
System..::.OperationCanceledExceptionIf the CancellationToken is canceled.
System..::.ArgumentNullExceptionThe collections argument is null.
System..::.ArgumentExceptionThe collections argument is a 0-length array or contains a null element, or at least one of collections has been marked as complete for adding.
System..::.ObjectDisposedExceptionAt least one of the BlockingCollection<(Of <(T>)>) instances has been disposed.
System..::.InvalidOperationExceptionAt least one underlying collection didn't accept the item.
System..::.ArgumentOutOfRangeExceptionThe count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

See Also